public class Vehicle {
    public String brand;
    public Vehicle(String brand) {
        this.brand = brand;
    }

    public void drive() {
        System.out.println(brand + " is driving.");
    }

    public String displayInfo() {
        return "Brand: " + brand;
    }
}
// 子类：小轿车
 class Car extends Vehicle {
    private int seatingCapacity;

    public Car(String brand, int seatingCapacity) {
        super(brand);  // 调用基类构造函数
        this.seatingCapacity = seatingCapacity;
    }

    @Override
    public void drive() {
        System.out.println(super.displayInfo() +" " + getBrand() + " car is driving with " + seatingCapacity + " passengers.");
    }

    @Override
    public String displayInfo() {
        return "Brand: " + getBrand() + ", Type: Car, Seating Capacity: " + seatingCapacity;
    }

    public String getBrand() {
        return super.brand; // 需要定义一个公开的方法以获取品牌信息
    }
}
// 子类：大货车
 class Truck extends Vehicle {
    private int cargoCapacity;

    public Truck(String brand, int cargoCapacity) {
        super(brand);
        this.cargoCapacity = cargoCapacity;
    }

    @Override
    public void drive() {
        System.out.println( super.displayInfo() + " " + getBrand() + " truck is driving with " + cargoCapacity + " kg cargo.");
    }

    @Override
    public String displayInfo() {
       return "Brand: " + getBrand() + ", Type: Truck, Cargo Capacity: " + cargoCapacity + " kg";
    }

    public String getBrand() {
        return super.brand;
    }
}
// 子类：客车
 class Bus extends Vehicle {
    private int passengerCapacity;

    public Bus(String brand, int passengerCapacity) {
        super(brand);
        this.passengerCapacity = passengerCapacity;
    }

    @Override
    public void drive() {
        System.out.println(super.displayInfo() + " " + getBrand() + " bus is driving with " + passengerCapacity + " passengers.");
    }

    @Override
    public String displayInfo() {
        return "Brand: " + getBrand() + ", Type: Bus, Passenger Capacity: " + passengerCapacity;
    }

    public String getBrand() {
        return super.brand;
    }
}
// 子类：自行车（设为final类，表示不希望被继承）
 final class Bicycle extends Vehicle {
    public Bicycle(String brand) {
        super(brand);
    }

    @Override
    public void drive() {
        System.out.println(super.displayInfo() + " " + getBrand() + " bicycle is pedaling.");
    }

    @Override
    public String displayInfo() {
        return "Brand: " + getBrand() + ", Type: Bicycle";
    }

    public String getBrand() {
        return super.brand;
    }
}


